package com.travel.server.manager.impl.sal;

import com.travel.common.CommonConstant;
import com.travel.common.excel.ExcelData;
import com.travel.common.util.DateUtil;
import com.travel.server.manager.model.CustomerInfo;
import com.travel.server.manager.model.MemberGradeInfo;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018\11\10 0010 18:21
 * @Desc:
 */
public class CustomerSal {

    /**
     * 判断是否会员
     * @param memberGradeInfo
     * @return
     */
    public static Integer isMember(MemberGradeInfo memberGradeInfo){
        if(memberGradeInfo.getName().contains(CommonConstant.NOT_MEMBER_STR)){
             return CommonConstant.NO;
        }else if(memberGradeInfo.getName().contains(CommonConstant.MEMBER_STR)){
            return CommonConstant.YES;
        }else{
            return CommonConstant.NO;
        }
    }

    public static String getCollectAddress(CustomerInfo customerInfo){
        String address = CommonConstant.EMPTY_STR;
        if(StringUtils.isNotBlank(customerInfo.getLiveProvince())){
            address = address + customerInfo.getLiveProvince() + CommonConstant.SPACE_STR;
        }
        if(StringUtils.isNotBlank(customerInfo.getLiveCity())){
            address = address + customerInfo.getLiveCity() + CommonConstant.SPACE_STR;
        }
        if(StringUtils.isNotBlank(customerInfo.getLiveArea())){
            address = address + customerInfo.getLiveArea() + CommonConstant.SPACE_STR;
        }
        if(StringUtils.isNotBlank(customerInfo.getLiveAddress())){
            address = address + customerInfo.getLiveAddress();
        }

        return address;
    }

    public static ExcelData makeExcelData(List<CustomerInfo> list){
        //姓名，手机号，性别，生日，微信号，邮箱，专业，爱好，工作行业，职业
        List<List<Object>> rows = new ArrayList<>();
        for(CustomerInfo customerInfo : list){
            List<Object> objectList = new ArrayList<>();
            objectList.add(customerInfo.getName());
            objectList.add(customerInfo.getMobile());
            objectList.add(customerInfo.getSex());
            if(customerInfo.getBirthDate() != null) {
                objectList.add(DateUtil.dateToStr(customerInfo.getBirthDate(), DateUtil.YYYY_MM_DD));
            }
            objectList.add(customerInfo.getWechatNumber());
            objectList.add(customerInfo.getMail());
            objectList.add(customerInfo.getMajor());
            objectList.add(customerInfo.getHobby());
            objectList.add(customerInfo.getWorkIndustry());
            objectList.add(customerInfo.getOccupation());
            rows.add(objectList);
        }
        List<String> title = Arrays.asList("姓名", "手机号", "性别", "生日", "微信号","邮箱", "专业", "爱好", "工作行业", "职业");
        ExcelData excelData = new ExcelData();
        excelData.setTitles(title);
        excelData.setRows(rows);
        excelData.setName("订单报表");
        return excelData;
    }
}
